//var urlcore = "http://192.168.1.100:8081";
 var urlcore="http://test.jiagangwangluo.com/jgsc";

var shuid = "";
var mingzi = "";
var pageSize = 8;
//var jumeiLogoUrl = 'http://app.jiagangwangluo.com/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/e5a3fa54-bc77-48d1-8c0c-cd711354ca80.jpg';
//引入微信js
/*document.write("<script language='javascript' src='http://res.wx.qq.com/open/js/jweixin-1.0.0.js'></script>");
document.write("<script language='javascript' src='https://res.wx.qq.com/open/js/jweixin-1.0.0.js'></script>");
document.write("<script language='javascript' src='http://www.jiagangwangluo.com/jgsc_wx/js/wx_util.js'></script>");
document.write("<script language='javascript' src='http://www.jiagangwangluo.com/jgsc_wx/js/base64.js'></script>");*/
/*var jumeiShareUrl = 'http://wx.jiagangwangluo.com/jgsc/';
var strShareUrl = "";
$(function() {
	var nowUrl = window.location.href;
	strShareUrl = nowUrl.substring(nowUrl.lastIndexOf("/") + 1);
	var strDesc = "我在家港，邀您享受生活美";
	if(document.title=="成功生成订单"){
		strDesc ="待客下单详情";
		strShareUrl="";
		var nowUrl2 =window.location.href+"&de=yes";
		strShareUrl ="sell/"+nowUrl2.substring(nowUrl2.lastIndexOf("/") + 1);
		alert("++"+strShareUrl);
	}else{
		strDesc =document.title;
	}
	
      wxShare(strShareUrl, strDesc);
})
*/

/**
 * 代客下单
 * **
 * */
/*function wxShare2(n) {
       var uset="http://wx.jiagangwangluo.com/wx/buy/12.8.2buy_dingdan_daikexiadan_detail.html"+n;
	$.ajax({
		url: urlcore + "/api/wxfenxiang/erweima?url="+uset,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				//微信参数
	getWxAccess();
	wx.ready(function() {
		// 2. 分享接口
		// 2.1 监听“分享给朋友”，按钮点击、自定义分享内容及分享结果接口
		wx.onMenuShareAppMessage({
			link: data.data,
			success: function(res) {
				alert('已分享');
			}
		});

		// 2.2 监听“分享到朋友圈”按钮点击、自定义分享内容及分享结果接口
		wx.onMenuShareTimeline({
			link: data.data,
			success: function(res) {
				alert('已分享');
			}
		});

		// 2.3 监听“分享到QQ”按钮点击、自定义分享内容及分享结果接口
		wx.onMenuShareQQ({
			link: data.data,
			success: function(res) {
				alert('已分享');
			}
		});
	});
			}else{
				alert(data.msg);
			}
		},
		error: function() {
			/* Act on the event 
			alert("error");
		}
	});
}*/

function wxShare(str, strDesc) {
	var parameter = str.replace(/\./g, "V");
	parameter = parameter.replace(/\&/g, "T");
	parameter = parameter.replace(/\?/g, "R");
	parameter = parameter + "V" + uuuuid;
	console.log(parameter);
	//微信参数
	//getWxAccess();
	wx.ready(function() {
		// 2. 分享接口
		// 2.1 监听“分享给朋友”，按钮点击、自定义分享内容及分享结果接口
		wx.onMenuShareAppMessage({
			title: strDesc,
			desc: " ",
			link: jumeiShareUrl + strShareUrl,
			imgUrl: jumeiLogoUrl,
			success: function(res) {
				alert('已分享');
			}
		});

		// 2.2 监听“分享到朋友圈”按钮点击、自定义分享内容及分享结果接口
		wx.onMenuShareTimeline({
			title: strDesc,
			desc: " ",
			link: jumeiShareUrl + strShareUrl,
			imgUrl: jumeiLogoUrl,
			success: function(res) {
				alert('已分享');
			}
		});
		// 2.3 监听“分享到QQ”按钮点击、自定义分享内容及分享结果接口
		wx.onMenuShareQQ({
			title: strDesc,
			desc: " ",
			link: jumeiShareUrl + strShareUrl,
			imgUrl: jumeiLogoUrl,
			success: function(res) {
				alert('已分享');
			}
		});
	});
}

/*
var useryemian=0;
alert(useryemian);
*/

//从url中获取参数值
function getvl(name) {
	var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
	if(reg.test(location.href.trim())) return unescape(RegExp.$2.replace(/\+/g, " "));
	return "";
};

//从url中获取参数值(解码汉字)
function getvl1(name) {
	var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
	if(reg.test(location.href.trim())) return decodeURI(RegExp.$2.replace(/\+/g, " "));
	return "";
};

//设置全局ajax
$.ajaxSetup({
	xhrFields: {
		withCredentials: true
	}
});

$(function() {
	//时间格式化
	Date.prototype.pattern = function(fmt) {
		var o = {
			"M+": this.getMonth() + 1, //月份         
			"d+": this.getDate(), //日         
			"h+": this.getHours(), //小时         
			"H+": this.getHours(), //小时         
			"m+": this.getMinutes(), //分         
			"s+": this.getSeconds(), //秒         
			"q+": Math.floor((this.getMonth() + 3) / 3), //季度         
			"S": this.getMilliseconds() //毫秒         
		};
		var week = {
			"0": "/u65e5",
			"1": "/u4e00",
			"2": "/u4e8c",
			"3": "/u4e09",
			"4": "/u56db",
			"5": "/u4e94",
			"6": "/u516d"
		};
		if(/(y+)/.test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		}
		if(/(E+)/.test(fmt)) {
			fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
		}
		for(var k in o) {
			if(new RegExp("(" + k + ")").test(fmt)) {
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
			}
		}
		return fmt;
	}
});

//初始化fileinput控件（第一次初始化）
function initFileInput(ctrlName, uploadUrl, okName, maxnNum) {
	var control = $('#' + ctrlName);
	control.fileinput({
		language: 'zh', //设置语言
		uploadUrl: uploadUrl, //上传的地址
		//uploadExtraData:{"id": 1, "fileName":'123.mp3'},
		resizeImage: true,
		resizePreference: 'width',
		resizeImageQuality: 0.2,
		uploadAsync: true, //默认异步上传
		showUpload: true, //是否显示上传按钮
		showRemove: true, //显示移除按钮
		showPreview: true, //是否显示预览
		showCaption: false, //是否显示标题
		browseClass: "btn btn-primary", //按钮样式     
		dropZoneEnabled: true, //是否显示拖拽区域
		maxFileCount: 10, //表示允许同时上传的最大文件个数
		dropZoneTitle: '拖拽文件到这里 &hellip;',
		enctype: 'multipart/form-data',
		validateInitialCount: true,
		previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
		msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
	}).on("fileuploaded", function(event, data, key) {
		if(data.response) {

			var okData = data.response.data;
			for(var i = 0; i < okData.length; i++) {
				var strHtml =
					'<div style="position:relative;width:250px;height:250px;float:left;display:none" id="' + key + '">' +
					'	<span onclick="removeStrHtml()" style="position:absolute;top:10px;right:10px;font-size:20px;color:#f00;" class="glyphicon glyphicon-trash" aria-hidden="true">' +
					'	</span>' +
					'	<img style="padding: 5px 5px 5px 5px;" width="250px" height="250px" src="' + okData[i] + '">' +
					'</div>';
				$(okName).append(strHtml);
			}
		}
	}).on('filesuccessremove', function(event, key) {
		$("#" + key).remove();
	});
}

//初始化fileinput控件（第一次初始化）
function initVideoInput(ctrlName, uploadUrl, okName, maxnNum) {
	var control = $('#' + ctrlName);

	control.fileinput({
		language: 'zh', //设置语言
		uploadUrl: uploadUrl, //上传的地址
		//uploadExtraData:{"id": 1, "fileName":'123.mp3'},
		uploadAsync: true, //默认异步上传
		showUpload: true, //是否显示上传按钮
		showRemove: true, //显示移除按钮
		showPreview: true, //是否显示预览
		showCaption: false, //是否显示标题
		browseClass: "btn btn-primary", //按钮样式     
		dropZoneEnabled: true, //是否显示拖拽区域
		maxFileCount: 10, //表示允许同时上传的最大文件个数
		dropZoneTitle: '拖拽文件到这里 &hellip;',
		enctype: 'multipart/form-data',
		validateInitialCount: true,
		previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
		msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
	}).on("fileuploaded", function(event, data, key) {
		if(data.response) {
			var okData = data.response.data;
			for(var i = 0; i < okData.length; i++) {
				var strHtml =
					'<div style="position:relative;width:250px;height:250px;float:left;display:none" id="' + key + '">' +
					'	<span onclick="removeStrHtml()" style="position:absolute;top:10px;right:10px;font-size:20px;color:#f00;" class="glyphicon glyphicon-trash" aria-hidden="true">' +
					'	</span>' +
					'	<video id="vd" width="150" height="150" controls="controls" src="' + okData[i] + '">' +
					'	</video>' +
					'</div>';
				$(okName).append(strHtml);
			}
		}
	}).on('filesuccessremove', function(event, key) {
		$("#" + key).remove();
	});
}

/**
 * 移除Html代码
 */
function removeStrHtml(obj) {
	$(obj).parent().remove();
}

//创建
var gc = gc || {};
gc.ajax = function(options) { //options =  {url:'',method:'',data:'',callback:'',async:''}
	//默认参数
	options.url = options.url || '',
		options.method = options.method || 'get',
		options.data = options.data || '',
		options.callback = options.callback || '',
		options.async = options.async || true;
	//get请求-拼接url
	if(options.method.toLowerCase() == 'get') {
		if(typeof options.data == 'object') {
			options.data = [];
			for(var k in options.data) {
				options.data.push(k + '=' + options.data[k]);
				options.data.join('&');
			}
		}
		options.url += (options.url.indexOf('?' == -1) ? '?' : '') + options.data;
	}
	//post请求-转换字符串
	if(options.method.toLowerCase() == 'post') {
		if(typeof options.data == 'object') {
			var arrs = [];
			for(var k in options.data) {
				arrs.push(k + '=' + options.data[k]);
			}
			options.data = arrs.join('&');
		}
	}
	//创建发送请求
	var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); //兼容ie
	xhr.open(options.method, options.url, options.async);
	if(options.method == 'post') {
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhr.send(options.data);
	} else {
		xhr.send(null);
	}
	//异步请求
	if(options.async == true) {
		xhr.onreadystatechange = function() {
			if(xhr.readyState == 4) {
				callcall();
			}
		}
	}
	// xhr.abort(); // 取消异步请求
	//同步请求
	if(options.async == false) {
		callcall();
	}
	//返回状态判断
	function callcall() {
		if(xhr.status == 200) {
			options.callback(xhr.responseText);
		} else {
			options.callback('error:' + xhr.status + xhr.statusText);
		}
	}
};

//删除数组元素
function removeByValue(arr, val) {
	for(var i = 0; i < arr.length; i++) {
		if(arr[i] == val) {
			arr.splice(i, 1);
			break;
		}
	}
}

//初始化fileinput控件（第一次初始化）
function initFileInput2(ctrlName, uploadUrl, okName, type) {

	if(type == 1) {
		// alert("有"+type);
		var control = $('#' + ctrlName);
		control.fileinput({
			jsFile: 'shows_admin/js/core.js', //当前js文件目录
			language: 'zh', //设置语言
			uploadUrl: uploadUrl, //上传的地址
			//uploadExtraData:{"type": type},
			uploadAsync: true, //默认异步上传
			showUpload: true, //是否显示上传按钮
			showRemove: true, //显示移除按钮
			showPreview: true, //是否显示预览
			showCaption: false, //是否显示标题
			browseClass: "btn btn-primary", //按钮样式     
			dropZoneEnabled: true, //是否显示拖拽区域
			maxFileCount: 10, //表示允许同时上传的最大文件个数
			maxImageWidth: 1000,
			maxImageHeight: null,
			resizeImage: true,
			resizePreference: 'width',
			dropZoneTitle: '拖拽文件到这里 &hellip;',
			enctype: 'multipart/form-data',
			validateInitialCount: true,
			previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
			msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
		}).on("fileuploaded", function(event, data, key) {
			if(data.response) {
				var okData = data.response.data;
				alert(".." + okData);

				var strId = JSON.stringify(okData);

				alert("..." + strId);
				var strText = $(okName).text();
				alert("...." + strText)
				if(strText == "") {
					$(okName).append(strId);
				} else {
					strId = strId + "*";
					$(okName).append(strId);
				}
				alert($(okName).text());

				//  $(okName).append(strHtml);
			}
		}).on('filesuccessremove', function(event, key) {
			var attId = document.getElementById(key).getElementsByTagName('div')[1].getElementsByTagName('button')[1].id;
			deleteAttachmentOne(attId, okName);
		});
	} else {

		alert("没有" + type);
		var control = $('#' + ctrlName);
		control.fileinput({
			language: 'zh', //设置语言
			uploadUrl: uploadUrl, //上传的地址
			//uploadExtraData:{"id": 1, "fileName":'123.mp3'},
			resizeImage: true,
			resizePreference: 'width',
			resizeImageQuality: 0.2,
			uploadAsync: true, //默认异步上传
			showUpload: true, //是否显示上传按钮
			showRemove: true, //显示移除按钮
			showPreview: true, //是否显示预览
			showCaption: false, //是否显示标题
			browseClass: "btn btn-primary", //按钮样式     
			dropZoneEnabled: true, //是否显示拖拽区域
			maxFileCount: 10, //表示允许同时上传的最大文件个数
			dropZoneTitle: '拖拽文件到这里 &hellip;',
			enctype: 'multipart/form-data',
			validateInitialCount: true,
			previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
			msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
		}).on("fileuploaded", function(event, data, key) {
			if(data.response) {

				var okData = data.response.data;
				for(var i = 0; i < okData.length; i++) {
					var strHtml =
						'<div style="position:relative;width:250px;height:250px;float:left;display:none" id="' + key + '">' +
						'	<span onclick="removeStrHtml()" style="position:absolute;top:10px;right:10px;font-size:20px;color:#f00;" class="glyphicon glyphicon-trash" aria-hidden="true">' +
						'	</span>' +
						'	<img style="padding: 5px 5px 5px 5px;" width="250px" height="250px" src="' + okData[i] + '">' +
						'</div>';
					$(okName).append(strHtml);
				}
			}
		}).on('filesuccessremove', function(event, key) {
			$("#" + key).remove();
		});
	}

}

function removeByValue(arr, val) { //删除数据的某个袁术
	for(var i = 0; i < arr.length; i++) {
		if(arr[i] == val) {
			arr.splice(i, 1);
			break;
		}
	}
}

var uuuuid = "";
var usertypeuser = "";
getOneAdmin();

function getOneAdmin() {
	$.ajax({
		url: urlcore + "/api/user/getadmin",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				if(data.data != null && data.data != "") {
					if(data.data.userType != 3) {
						uuuuid = data.data.id;
						usertypeuser = data.data.userType;
					}
				}
			}
		},
		error: function() {
			/* Act on the event */
			alert("error");
		}
	});
}

//优惠券
var youhuiquanname = "";
var youhuiquanid = "";

/* function errorImg(img) {
	img.src = "images/zanwutupian.png"; //http://static.xuexiba.com/uploadfile//UserInfo/Avatar/201403/1303992393385832875324.jpg
	img.onerror = null;
}

function errorImg2(img) {
	img.src = "../images/zanwutupian.png"; //http://static.xuexiba.com/uploadfile//UserInfo/Avatar/201403/1303992393385832875324.jpg
	img.onerror = null;
} */